package com.kikt.rxjavaandretrofit

import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.schedulers.Schedulers

/**
 * Created by cai on 2017/7/21.
 */
class MainPresenter(val view: MainView) : IPresenter {

    val model: MainModel = MainModelImpl()

    fun getRandom() {
        model.getRandom()
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe {
                    //                    logInfo("resp = $it")
//                    logInfo("error = ${it.isError}")
//                    logInfo("result = ")
                    it.results.forEach {
                        //                        logInfo("result = $it")
                    }
                }

        model.getDay(2016, 9, 1)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe {
                    //                    logInfo("result = $it")
                    logInfo(it.results.ios)
                    logInfo(it.results.android)
                    logInfo(it.results.recommend)
                    logInfo(it.results.restVideo)
                    logInfo(it.results.wellBeing)
                }

    }

    fun getCategory(item: String) {
        val count = 10
        val page = 10
        model.getCategory(item, count, page)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe {
                    logInfo("it = $it")
                    view.onUpdateData(it.results)
                }
    }


}